using System;
using UnityEngine;

namespace PlayerCtrl
{
    /// <summary>
    /// 保存玩家数据信息
    /// </summary>
    public class PlayerModel : Singleton<PlayerModel>
    {
        #region Variables

        private float _playerAttackDamage = 0;

        /**********    事件      **********/
        private event Action<PlayerModel> updateInfo; // 玩家数据改变后，更新UI面板

        #endregion

        #region InitData

        public void InitInfo()
        {
            // 存档数据初始化
            // playerCurrentLv = 1;
            // playerCurrentCoins = 100;
            // playerCurrentExp = 0;
            // currentHealth = 100;
            // playerMaxHealth = 100;
            // playerMaxExp = 100;
            // currentHealth = playerMaxHealth;

            // 数据初始化后通知UI面板进行更新
            UpdateInfo();
        }

        #endregion

        #region PlayerInformation

        /// <summary>
        /// 获取攻击伤害
        /// </summary>
        /// <returns></returns>
        public float GetPlayerAttackDamage()
        {
            if (_playerAttackDamage == 0)
                return PlayerInformation.PlayerAttackNormalValue;
            return PlayerInformation.PlayerAttackNormalValue + _playerAttackDamage;
        }

        public void SetPlayerAttackDamage(float damage)
        {
            _playerAttackDamage = damage;
        }

        #endregion

        #region EventAction

        /// <summary>
        /// 通知UI面板进行数据更新
        /// </summary>
        public void UpdateInfo()
        {
            updateInfo?.Invoke(this);
        }

        /// <summary>
        /// 添加事件
        /// </summary>
        /// <param name="action"></param>
        public void AddListener(Action<PlayerModel> action)
        {
            updateInfo += action;
        }

        /// <summary>
        /// 移除事件
        /// </summary>
        /// <param name="action"></param>
        public void RemoveListener(Action<PlayerModel> action)
        {
            updateInfo -= action;
        }

        #endregion

    }
}